<!DOCTYPE html>



  


<html class="theme-next gemini use-motion" lang="zh-Hans">
<head><meta name="generator" content="Hexo 3.8.0">
  <meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform">
<meta http-equiv="Cache-Control" content="no-siteapp">
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css">







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css">

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css">


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="docker,swarm,portainer,">










<meta name="description" content="title exampleTi-Client in Java [Under Construction]A Java client for TiDB/TiKV.It is supposed to:  Communicate via gRPC Talk to Placement Driver searching for a region Talk to TiKV for reading/writing">
<meta name="keywords" content="docker,swarm,portainer">
<meta property="og:type" content="article">
<meta property="og:title" content="test">
<meta property="og:url" content="https://chengxuwei.gitee.io/blog/2018/12/03/tidb exmaple/index.html">
<meta property="og:site_name" content="Code design">
<meta property="og:description" content="title exampleTi-Client in Java [Under Construction]A Java client for TiDB/TiKV.It is supposed to:  Communicate via gRPC Talk to Placement Driver searching for a region Talk to TiKV for reading/writing">
<meta property="og:locale" content="zh-Hans">
<meta property="og:updated_time" content="2018-12-03T12:16:00.000Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="test">
<meta name="twitter:description" content="title exampleTi-Client in Java [Under Construction]A Java client for TiDB/TiKV.It is supposed to:  Communicate via gRPC Talk to Placement Driver searching for a region Talk to TiKV for reading/writing">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Gemini',
    version: '5.1.4',
    sidebar: {"position":"right","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: '博主'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="https://chengxuwei.gitee.io/blog/2018/12/03/tidb exmaple/">





  <title>test | Code design</title>
  








</head>

<body itemscope="" itemtype="http://schema.org/WebPage" lang="zh-Hans">

  
  
    
  

  <div class="container sidebar-position-right page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope="" itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Code design</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br>
            
            首页
          </a>
        </li>
      
        
        <li class="menu-item menu-item-about">
          <a href="/blog/about/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-user"></i> <br>
            
            关于
          </a>
        </li>
      
        
        <li class="menu-item menu-item-tags">
          <a href="/blog/tags/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-tags"></i> <br>
            
            标签
          </a>
        </li>
      
        
        <li class="menu-item menu-item-categories">
          <a href="/blog/categories/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-th"></i> <br>
            
            分类
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br>
            
            归档
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope="" itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="https://chengxuwei.gitee.io/blog/blog/2018/12/03/tidb exmaple/">

    <span hidden itemprop="author" itemscope="" itemtype="http://schema.org/Person">
      <meta itemprop="name" content="Cheng xu wei">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.gif">
    </span>

    <span hidden itemprop="publisher" itemscope="" itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Code design">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">test</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">发表于</span>
              
              <time title="创建于" itemprop="dateCreated datePublished" datetime="2018-12-03T19:57:30+08:00">
                2018-12-03
              </time>
            

            

            
          </span>

          
            <span class="post-category">
            
              <span class="post-meta-divider">|</span>
            
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              
                <span class="post-meta-item-text">分类于</span>
              
              
                <span itemprop="about" itemscope="" itemtype="http://schema.org/Thing">
                  <a href="/blog/categories/服务界面/" itemprop="url" rel="index">
                    <span itemprop="name">服务界面</span>
                  </a>
                </span>

                
                
              
            </span>
          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <h1 id="title-example"><a href="#title-example" class="headerlink" title="title example"></a>title example</h1><h2 id="Ti-Client-in-Java-Under-Construction"><a href="#Ti-Client-in-Java-Under-Construction" class="headerlink" title="Ti-Client in Java [Under Construction]"></a>Ti-Client in Java [Under Construction]</h2><p>A Java client for <a href="https://github.com/pingcap/tidb" target="_blank" rel="noopener">TiDB</a>/<a href="https://github.com/pingcap/tikv" target="_blank" rel="noopener">TiKV</a>.<br>It is supposed to:</p>
<ul>
<li>Communicate via <a href="http://www.grpc.io/" target="_blank" rel="noopener">gRPC</a></li>
<li>Talk to Placement Driver searching for a region</li>
<li>Talk to TiKV for reading/writing data and the resulted data is encoded/decoded just like what we do in TiDB.</li>
<li>Talk to Coprocessor for calculation pushdown</li>
</ul>
<h2 id="How-to-build"><a href="#How-to-build" class="headerlink" title="How to build"></a>How to build</h2><p>The following command can install dependencies for you.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mvn package</span><br></pre></td></tr></table></figure></p>
<p>Alternatively, you can use <code>bazel</code> for much faster build. When you try this approach, you should run <code>git submodule update --init --recursive</code> before you build project.</p>
<p>Making a uber jar:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make uber_jar</span><br></pre></td></tr></table></figure></p>
<p>run Main class:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make run</span><br></pre></td></tr></table></figure></p>
<p>run test cases:<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">make test</span><br></pre></td></tr></table></figure></p>
<p>this project is designed to hook with <code>pd</code> and <code>tikv</code> which you can find in <code>PingCap</code> github page.</p>
<p>When you work with this project, you have to communicate with <code>pd</code> and <code>tikv</code>. There is a script taking care of this. By executing the following commands, <code>pd</code> and <code>tikv</code> can be executed on background.<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">cd scripts</span><br><span class="line">make pd</span><br><span class="line">make tikv</span><br></pre></td></tr></table></figure></p>
<h2 id="How-to-use-for-now"><a href="#How-to-use-for-now" class="headerlink" title="How to use for now"></a>How to use for now</h2><p>Since it’s not quite complete, a usage sample for now can be given is:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">// Init tidb cluster configuration</span></span><br><span class="line">TiConfiguration conf = TiConfiguration.createDefault(<span class="string">"127.0.0.1:2379"</span>);</span><br><span class="line">TiSession session = TiSession.create(conf);</span><br><span class="line">Catalog cat = session.getCatalog();</span><br><span class="line">TiDBInfo db = cat.getDatabase(<span class="string">"tpch_test"</span>);</span><br><span class="line">TiTableInfo table = cat.getTable(db, <span class="string">"customer"</span>);</span><br><span class="line">Snapshot snapshot = session.createSnapshot();</span><br><span class="line"> </span><br><span class="line"><span class="comment">// Generate select ranges</span></span><br><span class="line">ByteString startKey = TableCodec.encodeRowKeyWithHandle(table.getId(), Long.MIN_VALUE);</span><br><span class="line">ByteString endKey = TableCodec.encodeRowKeyWithHandle(table.getId(), Long.MAX_VALUE);</span><br><span class="line">Coprocessor.KeyRange keyRange = Coprocessor.KeyRange.newBuilder().setStart(startKey).setEnd(endKey).build();</span><br><span class="line">List&lt;Coprocessor.KeyRange&gt; ranges = <span class="keyword">new</span> ArrayList&lt;&gt;();</span><br><span class="line">ranges.add(keyRange);</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"><span class="comment">// Create select request</span></span><br><span class="line">TiSelectRequest selectRequest = <span class="keyword">new</span> TiSelectRequest();</span><br><span class="line">selectRequest.addRanges(ranges);</span><br><span class="line">selectRequest.addField(TiColumnRef.create(<span class="string">"c_mktsegment"</span>, table));</span><br><span class="line">selectRequest.setTableInfo(table);</span><br><span class="line">selectRequest.setStartTs(session.getTimestamp().getVersion());</span><br><span class="line">selectRequest.addWhere(<span class="keyword">new</span> GreaterEqual(TiConstant.create(<span class="number">5</span>), TiConstant.create(<span class="number">5</span>)));</span><br><span class="line">selectRequest.addGroupByItem(TiByItem.create(TiColumnRef.create(<span class="string">"c_mktsegment"</span>), <span class="keyword">false</span>));</span><br><span class="line">selectRequest.setLimit(<span class="number">10</span>);</span><br><span class="line">selectRequest.bind();</span><br><span class="line"> </span><br><span class="line"><span class="comment">// Fetch data</span></span><br><span class="line">Iterator&lt;Row&gt; iterator = snapshot.select(selectRequest);</span><br><span class="line">System.out.println(<span class="string">"Show result:"</span>);</span><br><span class="line"><span class="keyword">while</span> (iterator.hasNext()) &#123;</span><br><span class="line">  Row rowData = iterator.next();</span><br><span class="line">  <span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i &lt; rowData.fieldCount(); i++) &#123;</span><br><span class="line">    System.out.print(rowData.get(i, <span class="keyword">null</span>) + <span class="string">"\t"</span>);</span><br><span class="line">  &#125;</span><br><span class="line">  System.out.println();</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>Result:<br><figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">Show result:</span><br><span class="line">BUILDING	</span><br><span class="line">AUTOMOBILE	</span><br><span class="line">MACHINERY	</span><br><span class="line">HOUSEHOLD	</span><br><span class="line">FURNITURE</span><br></pre></td></tr></table></figure></p>
<h2 id="TODO"><a href="#TODO" class="headerlink" title="TODO"></a>TODO</h2><p>Contributions are welcomed. Here is a <a href="https://github.com/pingcap/tikv-client-java/wiki/TODO-Lists" target="_blank" rel="noopener">TODO</a> and you might contact <a href="mailto:maxiaoyu@pingcap.com" target="_blank" rel="noopener">maxiaoyu@pingcap.com</a> if needed.</p>
<h2 id="License"><a href="#License" class="headerlink" title="License"></a>License</h2><p>Apache 2.0 license. See the <a href="./LICENSE">LICENSE</a> file for details.</p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      
        <div class="post-tags">
          
            <a href="/blog/tags/docker/" rel="tag"># docker</a>
          
            <a href="/blog/tags/swarm/" rel="tag"># swarm</a>
          
            <a href="/blog/tags/portainer/" rel="tag"># portainer</a>
          
        </div>
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/06/07/hello-world/" rel="next" title="hello world">
                <i class="fa fa-chevron-left"></i> hello world
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/12/03/Portainer与Swarm集群/" rel="prev" title="Portainer与Swarm集群">
                Portainer与Swarm集群 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      
        <ul class="sidebar-nav motion-element">
          <li class="sidebar-nav-toc sidebar-nav-active" data-target="post-toc-wrap">
            文章目录
          </li>
          <li class="sidebar-nav-overview" data-target="site-overview-wrap">
            站点概览
          </li>
        </ul>
      

      <section class="site-overview-wrap sidebar-panel">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope="" itemtype="http://schema.org/Person">
            
              <p class="site-author-name" itemprop="name">Cheng xu wei</p>
              <p class="site-description motion-element" itemprop="description"></p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">8</span>
                  <span class="site-state-item-name">日志</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-categories">
                <a href="/blog/categories/index.html">
                  <span class="site-state-item-count">9</span>
                  <span class="site-state-item-name">分类</span>
                </a>
              </div>
            

            
              
              
              <div class="site-state-item site-state-tags">
                <a href="/blog/tags/index.html">
                  <span class="site-state-item-count">15</span>
                  <span class="site-state-item-name">标签</span>
                </a>
              </div>
            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      
      <!--noindex-->
        <section class="post-toc-wrap motion-element sidebar-panel sidebar-panel-active">
          <div class="post-toc">

            
              
            

            
              <div class="post-toc-content"><ol class="nav"><li class="nav-item nav-level-1"><a class="nav-link" href="#title-example"><span class="nav-number">1.</span> <span class="nav-text">title example</span></a><ol class="nav-child"><li class="nav-item nav-level-2"><a class="nav-link" href="#Ti-Client-in-Java-Under-Construction"><span class="nav-number">1.1.</span> <span class="nav-text">Ti-Client in Java [Under Construction]</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#How-to-build"><span class="nav-number">1.2.</span> <span class="nav-text">How to build</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#How-to-use-for-now"><span class="nav-number">1.3.</span> <span class="nav-text">How to use for now</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#TODO"><span class="nav-number">1.4.</span> <span class="nav-text">TODO</span></a></li><li class="nav-item nav-level-2"><a class="nav-link" href="#License"><span class="nav-number">1.5.</span> <span class="nav-text">License</span></a></li></ol></li></ol></div>
            

          </div>
        </section>
      <!--/noindex-->
      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Cheng xu wei</span>

  
</div>


  <div class="powered-by">由 <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a> 强力驱动</div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">主题 &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Gemini</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
